*******************************************************
* Replication Code for:
* Paying It Forward: Generalized Reciprocity in Mass Opinion on Foreign Aid - Public Opinion Quarterly
* Author: Joonbum Bae and Changkeun Lee
* Stata Version: 17+
* Notes:
* - Outputs all tables in the /output folder
* - All filenames are fixed (no date stamps)
* - Deletes any previous output files with same name
*******************************************************

clear all
set more off
version 17

* === Set working directory ===
cd "PATH/TO/REPLICATION/FOLDER"

* === Load data ===
use "bae_lee_replication.dta", clear

* === Ensure output folder exists ===
cap mkdir output

*******************************************************
* 0. VARIABLE CREATION
*******************************************************

* Johnson & Johnson (J&J) vaccination indicator
gen jans = (vactype == 4) 

* Other vaccines indicator (valid types <6 and not J&J)
gen othervac = (vactype < 6 & jans == 0)

* J&J eligibility based on Korean policy: age >=30 and male
gen jans_elig = (age >= 30) & (female == 0)

* Age-based J&J eligibility only (used for IV robustness)
gen jans_elig_age = (age >= 30)

* New vaccination between waves
gen newvacc = w2_vaccf - w1_vacc
 
* Dependent variables: changes between waves
gen d_feelUS = w2_y1 - w1_y1
gen d_vaid   = w2_y2 - w1_y2 if qtype == 1 | qtype == 3

*******************************************************
* 1. TABLE 1: Key Sample Descriptives
*******************************************************
* Descriptive statistics for key variables
tabstat w1_vacc w2_vaccf newvacc female age pol if wave2, stat(n mean sd) col(stat)

* Vaccination rates at Wave 1 by age group
tab agegroup w1_vacc, row

*******************************************************
* 2. TABLE 2
*******************************************************
table agegroup, stat(mean w1_vacc jans w2_vaccf)
tabstat w1_vacc w2_vaccf newvacc female age pol if wave2, stat(n mean sd) col(stat)
tabstat w1_y1 w2_y1 d_feelUS w2_y1 w2_y2 d_vaid if wave2, stat(n mean sd) col(stat)

*******************************************************
* 3. TABLE 3
*******************************************************
eststo clear
eststo: reg w1_y2 w1_vacc female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w1_y2 w1_vacc w1_vacc_us female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w1_y2 w1_vacc female i.agegroup i.edu i.pol if agegroup < 5, vce(robust)
eststo: reg w1_y2 w1_vacc w1_vacc_us female i.agegroup i.edu i.pol if agegroup < 5, vce(robust)
eststo: reg w2_y2 w2_vaccf usinfo female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w2_y2 w2_vaccf w2_vaccf_us usinfo female i.agegroup i.edu i.pol, vce(robust)
esttab using "output/T3.csv", label b(%4.3f) r2 nogaps p nostar scalars(F p_value) replace

*******************************************************
* 4. TABLE 4
*******************************************************
eststo clear
eststo: reg d_feelUS newvacc##i.pol if w2_vaccf == 1, vce(robust)
eststo: reg d_feelUS newvacc##i.pol female i.agegroup i.edu i.pol if w2_vaccf == 1, vce(robust)
eststo: reg d_vaid newvacc##i.pol usinfo if w2_vaccf == 1, vce(robust)
eststo: reg d_vaid newvacc##i.pol usinfo female i.agegroup i.edu i.pol if w2_vaccf == 1, vce(robust)
eststo: reg w2_y1 w2_vaccf usinfo##i.pol female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w2_y1 w2_vaccf w2_vaccf_us usinfo##i.pol female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w2_y2 w2_vaccf usinfo##i.pol female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w2_y2 w2_vaccf w2_vaccf_us usinfo##i.pol female i.agegroup i.edu i.pol, vce(robust)
esttab using "output/T4.csv", label b(%4.3f) r2 nogaps p nostar scalars(F p_value) replace

*******************************************************
* 5. TABLE 5
*******************************************************
eststo clear
eststo: reg w1_y1 jans_elig othervac female i.edu i.pol if age >=27 & age <=32 , vce(robust)
eststo: reg w1_y1 jans othervac female i.edu i.pol if age >=27 & age <=32 , vce(robust)
eststo: ivregress 2sls w1_y1 (jans = jans_elig) female othervac i.edu i.pol if age >=27 & age <=32 , vce(robust)
eststo: reg w1_y2 jans_elig othervac female i.edu i.pol if age >=27 & age <=32 , vce(robust)
eststo: reg w1_y2 jans othervac female i.edu i.pol if age >=27 & age <=32 , vce(robust)
eststo: ivregress 2sls w1_y2 (jans = jans_elig) female othervac i.edu i.pol if age >=27 & age <=32 , vce(robust)
eststo: reg w1_y1 jans_elig othervac i.edu i.pol if age >=27 & age <=32  & female==0, vce(robust)
eststo: reg w1_y1 jans othervac i.edu i.pol if age >=27 & age <=32  & female==0, vce(robust)
eststo: ivregress 2sls w1_y1 (jans = jans_elig_age) othervac i.edu i.pol if age >=27 & age <=32 & female==0, vce(robust)
eststo: reg w1_y2 jans_elig othervac  i.edu i.pol if age >=27 & age <=32  & female==0, vce(robust)
eststo: reg w1_y2 jans othervac  i.edu i.pol if age >=27 & age <=32  & female==0, vce(robust)
eststo: ivregress 2sls w1_y2 (jans = jans_elig_age) othervac i.edu i.pol if age >=27 & age <=32 & female==0, vce(robust)
esttab using "output/T5.csv", drop(*edu*) label b(%4.3f) r2 nogaps p nostar scalars(F p_value) replace

*******************************************************
* APPENDIX TABLE A1
*******************************************************
eststo clear
eststo: reg wave2 female ib5.agegroup i.edu i.pol, vce(robust)
eststo: reg wave2 w1_y1 female ib5.agegroup i.edu i.pol, vce(robust)
eststo: reg wave2 w1_y2 female ib5.agegroup i.edu i.pol, vce(robust)
eststo: logit wave2 female ib5.agegroup i.edu i.pol, vce(robust)
eststo: logit wave2 w1_y1 female ib5.agegroup i.edu i.pol, vce(robust)
eststo: logit wave2 w1_y2 female ib5.agegroup i.edu i.pol, vce(robust)
esttab using "output/aT1_retention.csv", label b(%4.3f) r2 nogaps p nostar replace

*******************************************************
* APPENDIX TABLE A2
*******************************************************
eststo clear
eststo: reg w1_y1 w1_vacc female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w1_y1 w1_vacc w1_vacc_us  female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w1_y1 w1_vacc female i.agegroup i.edu i.pol if agegroup < 5, vce(robust)
eststo: reg w1_y1 w1_vacc w1_vacc_us female i.agegroup i.edu i.pol if agegroup < 5, vce(robust)
eststo: reg w2_y1 w2_vaccf female i.agegroup i.edu i.pol, vce(robust)
eststo: reg w2_y1 w2_vaccf w2_vaccf_us female i.agegroup i.edu i.pol, vce(robust)
eststo: reg d_feelUS newvacc if w2_vaccf == 1, vce(robust)
eststo: reg d_feelUS newvacc female i.agegroup i.edu i.pol if w2_vaccf == 1, vce(robust)
esttab using "output/aT2_view_US.csv", label b(%4.3f) p r2 nogaps scalars(F p_value) nostar replace

*******************************************************
* APPENDIX TABLE A3 & A4
*******************************************************
gen vac_origin_correct = .
replace vac_origin_correct = 0 if w1_vacc == 1
replace vac_origin_correct = 1 if vac_country_uk == 1 & vactype == 2
replace vac_origin_correct = 1 if vac_country_us == 1 & (vactype == 1 | vactype == 3 | vactype == 4)
replace vac_origin_correct = 1 if vac_country_ger == 1 & (vactype == 1)
table vactype, stat(mean vac_country*)

eststo clear
eststo: reg w1_y1 w1_vacc female i.agegroup i.edu i.pol  if vac_origin_correct !=0, vce(robust)
eststo: reg w1_y1 w1_vacc w1_vacc_us  female i.agegroup i.edu i.pol  if vac_origin_correct !=0, vce(robust)
eststo: reg w1_y1 w1_vacc female i.agegroup i.edu i.pol if agegroup < 5  & vac_origin_correct !=0, vce(robust)
eststo: reg w1_y1 w1_vacc w1_vacc_us female i.agegroup i.edu i.pol if agegroup < 5  & vac_origin_correct !=0, vce(robust)
eststo: reg w2_y1 w2_vaccf female i.agegroup i.edu i.pol  if vac_origin_correct !=0, vce(robust)
eststo: reg w2_y1 w2_vaccf w2_vaccf_us female i.agegroup i.edu i.pol  if vac_origin_correct !=0, vce(robust)
eststo: reg d_feelUS newvacc if w2_vaccf == 1 & vac_origin_correct !=0, vce(robust)
eststo: reg d_feelUS newvacc female i.agegroup i.edu i.pol if w2_vaccf == 1 & vac_origin_correct !=0, vce(robust)
esttab using "output/aT4_origin_test.csv", label b(%4.3f) r2 nogaps p nostar scalars(F p_value) replace

*******************************************************
* APPENDIX TABLE A5
*******************************************************
eststo clear
eststo: reg d_vaid newvacc usinfo if w2_vaccf == 1, vce(robust)
eststo: reg d_vaid newvacc usinfo female i.agegroup i.edu i.pol if w2_vaccf == 1, vce(robust)
esttab using "output/aT5_difference.csv", label b(%4.3f) r2 nogaps p nostar scalars(F p_value) replace

*******************************************************
* END SCRIPT
*******************************************************
di as txt "Replication script completed successfully."
